/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.wdm.utils;

import com.google.gson.*;
import java.lang.reflect.Type;
import org.wdm.beans.points.BusStopPoint;
import org.wdm.beans.points.Point;

/**
 *
 * @author thanasis
 */
public class PointDeserializer implements JsonDeserializer<Point>
{
  @Override
  public Point deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException
  {
      JsonObject job = json.getAsJsonObject();
      double latitude = job.get("latitude").getAsDouble();
      double longitude = job.get("longitude").getAsDouble();
      String pointType = job.get("pointType").getAsString();
      if(pointType.equals("BusStop")){
          String naptanAtco = job.get("naptanAtco").getAsString();
            String name = job.get("name").getAsString();
            String busRoute = job.get("busRoute").getAsString();
            return new BusStopPoint(naptanAtco, name, busRoute, latitude, longitude);
      }
    
    return new Point(latitude, longitude, pointType);
  }
} 